﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using fanfu.Common;
using fanfu.Model;
using System.Data.SqlClient;

namespace fanfu.Business
{
    public class SystemMenuRule
    {
        #region 获取所有系统菜单信息
        /// <summary>
        /// 获取所有系统菜单信息
        /// </summary>
        public DataTable GetAllSystemMenuInfo()
        {
            string sqlString = "SELECT * FROM SystemMenu ORDER BY ParentId ASC, Ord ASC";
            DataTable dt = SqlHelper.GetDataTable(sqlString);
            return dt;
        }
        #endregion

        #region 获取指定ID的系统菜单
        /// <summary>
        /// 获取指定ID的系统菜单
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public SystemMenuModel GetSystemMenuByID(string ID)
        {
            string sqlString = "SELECT TOP 1 * FROM SystemMenu WHERE ID=@ID";
            SqlParameter para = new SqlParameter("@ID", ID);
            DataTable dt = SqlHelper.GetDataTable(sqlString, para);
            if (dt.Rows.Count == 1)
                return new SystemMenuModel(dt.Rows[0]);
            else
                return null;
        }
        #endregion

        #region 删除指定ID的系统菜单
        /// <summary>
        /// 删除指定ID的系统菜单
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public int DeleteSystemMenu(string ID)
        {
            string sqlString = string.Format("UPDATE SystemMenu SET Flag={0} WHERE ID={1}", (int)SystemMenuFlag.delete, ID);
            return SqlHelper.ExecuteCommand(sqlString);
        }
        #endregion
    }
}
